﻿function selrd(e)
{
       if(e.checked)
       {
       $('divr').style.display="";
       $('rd1').checked=true;
       }else
       {
        $('divr').style.display="none";
        for(var i=1;i<7;i++)
        {
            $('rd'+i).checked=false;
        }
       }
}
function cucancel()
{
 var refer = document.referrer.toLowerCase();
    if(refer=="")
    {
        top.location = "/";
    }    
    else
    {
        window.location.href = refer;
    }
}
function savecourse()
{
showProgressBar(true);
$("ErrorDesc").style.display = "none";
$('Smt').style.display = "none";
$("ErrorTags").style.display = "none";

var license="";
for(var i=0;i<7;i++)
{
    if($('rd'+i).checked)
    {
      license=$('rd'+i).value;  
    }
}
var baselanguage = "";
var tmelments = $("mt").getElementsByTagName("input");
for (var i = 0; i < tmelments.length; i++)
    {
        if(tmelments[i].type=="checkbox" && tmelments[i].checked)
        {
            baselanguage += tmelments[i].value+"|";
        }
    }
 var valDesc = "";//内容    
try{valDesc=FCKeditorAPI.GetInstance('txtDesc').GetXHTML(true);}catch(e){} 
var tags = $("TagsText").value;
var varTags = "";
var elments = $("tbTag").getElementsByTagName("input");
for (var i = 0; i < elments.length; i++)
    {
        if(elments[i].type=="checkbox" && elments[i].checked)
        {
            varTags += elments[i].value+" ";
        }
    }
  var tagArr = tags.split(" ");
  var isvaltag=false;
  if(tags.indexOf("-")!=-1||tags.indexOf("/")!=-1)
    {
       isvaltag=true;
    }
   for(var i = tagArr.length-1; i >=0; i--)
    {
        if(tagArr[i].length > 50)
        {
            isvaltag=true;
        }
    }    
    varTags += tags;
    if(varTags.split(" ").length>25)
    {
       isvaltag=true;
    }
if(!$ValidButton$()||valDesc.length<3 || valDesc.length>9999||isvaltag||baselanguage=="")
{
    if(valDesc.length<3 || valDesc.length>9999)
    {
        $("ErrorDesc").style.display = "";
    }
    if(isvaltag)
    {
        $("ErrorTags").style.display = "";
    }
    if(baselanguage=="")
    {
        $('Smt').style.display = "";
    }
    showProgressBar(false);
    return;
}
var level="";
var st=$('sleto').value;
var sf=$('slefrom').value;
for(var i=sf;i<=st;i++)
{
    level+=i+"";
}
var ctype=$('CType').value;
var Price=$('tPrice').value;
var IsProFree=$('IsProFree').checked;
var IsProDiscount=$('IsProDiscount').checked;

baselanguage=baselanguage.substring(0,baselanguage.length-1);
     WebServices.User.Teach.AddCourse($('CourseText').value,valDesc,$('selLanguageLearn').value,level,baselanguage,license,ctype,Price,IsProFree,IsProDiscount,varTags,onsucc);
    
}
function onsucc(result)
{
showProgressBar(false);
   if(result==-1)
   {
     alert('ssss');
   }else
   {
    top.location="/course/"+result;
   } 
}